#ifndef CROWDSIMFRAMELISTENER_H
#define CROWDSIMFRAMELISTENER_H

#include "OGRE/ExampleApplication.h"
#include "RVO/RVO.h"

struct RoadmapVertex {
	RVO::Vector2 position;
	std::vector<int> neighbors;
	std::vector<float> distToGoal;
};

class CrowdSimFrameListener : public ExampleFrameListener
{
public:
	CrowdSimFrameListener(SceneManager *sceneMgr, 
		RenderWindow* win, 
		Camera* cam);
	RVO::RVOSimulator *sim;
	std::vector<RoadmapVertex> roadmap;
	std::vector<int> goals;
	std::vector<Ogre::Entity*> ents;
	bool isStarted;
	bool isFrameMode;
	bool isGraphMode;
	void updateVisualization(RVO::RVOSimulator* sim,const FrameEvent& evt);
	void setPreferredVelocities(RVO::RVOSimulator* sim);
	bool reachedGoal(RVO::RVOSimulator* sim);
	void buildRoadmap(RVO::RVOSimulator* sim);
	char *readCFG();
	virtual bool processUnbufferedKeyInput(const FrameEvent& evt);
private:
	SceneManager* mSceneMgr;
	std::vector<SceneNode*> nodes;
	bool frameStarted(const FrameEvent& evt);
	bool frameEnded(const FrameEvent& evt);
	SceneNode* createBall(Vector3&pos,int ballType);
	bool initMain();
	bool initFrame();
	bool isCrazyMood;
private:
	SceneNode* _mainNode;
	SceneNode* _frameNode;
	SceneNode* _graphNode;
	SceneNode* _envNode;
	SceneNode* _crazyNode;
	Ogre::StaticGeometry *_sg;
	const static int BALL_ANCHOR=0;
	const static int BALL_OBS=1;
	float _groundHeight;
	int timeStep;
	float scaleFac;
	std::vector<float> maxspeeds;
};
#endif